﻿
//关闭当前页 返回父页面
function closePage(isReload) {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index); //再执行关闭
    if (isReload) {
        parent.search();
    }
}

layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = layui.layer;

    $(function () {
        var pid = app.getRequest('ParentId');
        if (pid) {
            $('#tbParentId').val(pid)
        }
        if (app.getRequest('GUID')) {
            initData();
        }
    });

    //初始化表单
    function initData() {
        var fieldData = {
            GUID: app.getRequest('GUID'),
            PostType: "get",
            ActionType: "Menu"
        };
        app.loadData("MenuManage.ashx", fieldData, function (data) {
            form.render();
        }, function (err) {
            layer.msg('请求失败');
        });
    }

    //保存
    form.on('submit(save)', function (data) {
        var fieldData = data.field;
        fieldData["GUID"] = app.getRequest('GUID');
        fieldData["ActionType"] = "Menu";
        app.set("MenuManage.ashx", fieldData, function (data) {
            layer.msg(data.msg);
            if (data.success) {
                setTimeout(function () {
                    closePage(true);
                }, 1000);
            }
        }, function (err) {
            layer.msg('请求失败');
        });
        return false;
    });
});
